{% set pypi_name = 'neutron-vpnaas' %}
{% set source = fetch_source('https://tarballs.openstack.org/neutron-vpnaas/neutron-vpnaas-master.tar.gz') %}
{% set upstream_version = upstream_version() %}
{% set rpm_release = '1' %}
Name:           {{ py2name() }}
Epoch:          {{ epoch('neutron') }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        OpenStack Neutron VPN Service
License:        {{ license('Apache-2.0') }}
URL:            https://docs.openstack.org/neutron
Source0:        {{ source|basename }}
# systemd service files
Source10:       openstack-neutron-vyatta-agent.service
BuildRequires:  openstack-macros
BuildRequires:  {{ py2pkg('neutron') }}
BuildRequires:  {{ py3('pbr') }}
Requires:       python3-{{ pypi_name }} = %{epoch}:%{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  systemd-rpm-macros
%{?systemd_requires}
%else
BuildRequires:  systemd
Requires(post): systemd
Requires(postun): systemd
Requires(preun): systemd
%endif

%description
Neutron is a virtual network service for Openstack.
This is a VPN service plugin for Openstack Neutron (Networking) service.

%package -n python3-{{ pypi_name }}
Summary:        Neutron VPN Python libraries
Group:          Development/Languages/Python
Requires:       {{ py2pkg('neutron') }}
Requires:       {{ py3('Jinja2') }}
Requires:       {{ py3('SQLAlchemy') }}
Requires:       {{ py3('alembic') }}
Requires:       {{ py3('netaddr') }}
Requires:       {{ py3('neutron-lib') }}
Requires:       {{ py3('oslo.concurrency') }}
Requires:       {{ py3('oslo.config') }}
Requires:       {{ py3('oslo.db') }}
Requires:       {{ py3('oslo.log') }}
Requires:       {{ py3('oslo.messaging') }}
Requires:       {{ py3('oslo.reports') }}
Requires:       {{ py3('oslo.serialization') }}
Requires:       {{ py3('oslo.service') }}
Requires:       {{ py3('oslo.utils') }}
Requires:       {{ py3('pbr') }}
Requires:       {{ py3('requests') }}
Requires:       {{ py3('six') }}

%description -n   python3-{{ pypi_name }}
Neutron is a virtual network service for Openstack.
This is a VPN service plugin for Openstack Neutron (Networking) service.

This package contains the Neutron VPN Python library.

%package doc
Summary:        Neutron VPN as a Service - Documentation
Group:          Documentation/HTML
BuildRequires:  {{ py3('Sphinx') }}
BuildRequires:  {{ py3('openstackdocstheme') }}

%description doc
Neutron is a virtual network service for Openstack.
This is a VPN service plugin for Openstack Neutron (Networking) service.

This package contains the Neutron VPN documentation.

%package -n openstack-neutron-vyatta-agent
Summary:        Neutron VPN as a Service - Load Balancing Agent for Brocade Vyatta
Group:          Development/Languages/Python
Requires:       %{name} = %{epoch}:%{version}-%{release}

%description -n openstack-neutron-vyatta-agent
Neutron is a virtual network service for Openstack.
This is a VPN service plugin for Openstack Neutron (Networking) service.

This package contains the Brocade Vyatta agent

%prep
%autosetup -p1 -n {{ pypi_name }}-{{upstream_version}}
%py_req_cleanup

%build
%py3_build

# generate html docs
PYTHONPATH=$PWD PBR_VERSION={{ upstream_version }} %sphinx_build --keep-going -b html doc/source doc/build/html
# remove the Sphinx-build leftovers
rm -rf doc/build/html/.{doctrees,buildinfo}

%install
%py3_install

### configuration files
for x in `ls etc/oslo-config-generator/*`; do
    PYTHONPATH=. oslo-config-generator --config-file $x
done

install -p -D -m 644 etc/neutron_vpnaas.conf.sample %{buildroot}%{_sysconfdir}/neutron/neutron_vpnaas.conf
install -p -D -m 644 etc/vpn_agent.ini.sample %{buildroot}%{_sysconfdir}/neutron/vpn_agent.ini

# move wrongly installed files from /usr/etc to /etc
install -d -m 755 %{buildroot}%{_datarootdir}/neutron/rootwrap
mv %{buildroot}/%{_prefix}/%{_sysconfdir}/neutron/rootwrap.d/* %{buildroot}%{_datarootdir}/neutron/rootwrap

### systemd
mkdir -p %{buildroot}%{_sbindir} %{buildroot}%{_unitdir}
install -p -D -m 444 %{SOURCE10} %{buildroot}%{_unitdir}/openstack-neutron-vyatta-agent.service
%if 0%{?suse_version}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcopenstack-neutron-vyatta-agent
%endif

%post -n openstack-neutron-vyatta-agent
%systemd_post openstack-neutron-vyatta-agent.service

%preun -n openstack-neutron-vyatta-agent
%systemd_preun openstack-neutron-vyatta-agent.service

%postun -n openstack-neutron-vyatta-agent
%systemd_postun_with_restart openstack-neutron-vyatta-agent.service

%files
%license LICENSE
%doc README.rst
%config(noreplace) %{_sysconfdir}/neutron/neutron_vpnaas.conf
%config(noreplace) %{_sysconfdir}/neutron/vpn_agent.ini
%dir %{_datarootdir}/neutron/rootwrap
%{_datarootdir}/neutron/rootwrap/vpnaas.filters
%{_bindir}/neutron-vpn-netns-wrapper

%files -n python3-{{ pypi_name }}
%license LICENSE
%{python3_sitelib}/neutron_vpnaas
%{python3_sitelib}/neutron_vpnaas-*.egg-info

%files doc
%license LICENSE
%doc doc/build/html

%files -n openstack-neutron-vyatta-agent
%license LICENSE
%{_unitdir}/openstack-neutron-vyatta-agent.service
%if 0%{?suse_version}
%{_sbindir}/rcopenstack-neutron-vyatta-agent
%endif

%changelog
